package com.qf.efserver.user.personaldata.controller;

import com.qf.common.core.common.R;
import com.qf.efserver.login.param.StatureParam;
import com.qf.efserver.user.personaldata.param.UsersUpdateParam;
import com.qf.efserver.user.personaldata.service.UsersService;
import com.qf.efserver.user.personaldata.service.UsersWeightService;
import com.qf.efserver.user.personaldata.vo.UsersDataVO;
import com.qf.efserver.user.personaldata.vo.WeightVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * ---做一个内核强大的人---
 *
 * @author HuaZi
 * @date 2024/11/8
 * @desc 希望我们都能遇到真诚的人
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户api")
public class UserController {
    @Resource
    private UsersService usersService;
    @Resource
    private UsersWeightService usersWeightService;

    @ApiOperation(value = "新用户登录设置身体数据",notes = "首次进入页面时选择性别和年龄")
    @PostMapping("/stature")
    public R userStature(@RequestBody StatureParam statureParam) {
        usersService.updateUserStature(statureParam);
        return R.ok();
    }

    @ApiOperation(value = "获取用户展示信息",notes = "根据token中的uid展示用户信息")
    @GetMapping("/getData")
    public R<UsersDataVO> getUserData() {
        UsersDataVO usersDataVO = usersService.getUserVO();
        return R.ok(usersDataVO);
    }

    @ApiOperation(value = "修改密码",notes = "根据token中的uid用户修改密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "password", value = "用户第一次输入的密码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "verifyPassword", value = "用户第二次输入的密码", required = true, dataType = "String")
    })
    @PostMapping("/updatePwd")
    public R updatePassword(String password,String verifyPassword){
        usersService.updatePassword(password, verifyPassword);
        return R.ok();
    }
    @ApiOperation(value = "用户体重展示",notes = "根据token中的uid展示体重")
    @GetMapping("/getWeight")
    public R<List<WeightVO>> getWeight() {
        List<WeightVO> weights = usersWeightService.getWeights();
        return R.ok(weights);
    }
    @ApiOperation(value = "新增体重",notes = "根据token中的uid修改体重")
    @ApiImplicitParam(name = "weight", value = "体重", required = true, dataType = "double", paramType = "path")
    @PostMapping("/insertWeight")
    public R insertWeight(Double weight) {
        usersWeightService.insertWeight(weight);
        return R.ok();
    }

    @ApiOperation(value = "更新体重",notes = "更新体重")
    @PostMapping("/updateWeight")
    public R updateWeight() {
        usersWeightService.updateWeight();
        return R.ok();
    }

    @ApiOperation(value = "修改用户信息",notes = "修改用户信息")
    @ApiImplicitParam(name = "UsersUpdateParam", value = "用户修改类", required = true, dataType = "UsersUpdateParam")
    @PostMapping("/updateUsers")
    public R updateUsers(@RequestBody UsersUpdateParam usersUpdateParam) {
        usersService.updateUsers(usersUpdateParam);
        return R.ok();
    }

    @ApiOperation("上传头像")
    @PostMapping("/upload")
    public R<String> uploadAvatar(@RequestPart("file") MultipartFile file) {
        String path = usersService.upload(file);
        return R.ok(path);
    }
}
